package com.xh.utils;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 图片工具类
 */
public class ImageUtil {

    /**
     * 合成纯色背景图
     *
     * @param width  宽度
     * @param height 高度
     */
    public static BufferedImage createBackgroundImg(int width, int height) {
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        return writeImage(bufferedImage);
    }


    /**
     * 通过指定参数写一个图片
     */
    private static BufferedImage writeImage(BufferedImage image) {
        Graphics g = image.getGraphics();
        g.setColor(new Color(255, 255, 255));
        for (int i = 0; i < image.getWidth(); i++) {
            for (int j = 0; j < image.getHeight(); j++) {
                g.drawLine(i, j, image.getWidth(), image.getHeight());
            }
        }
        g.dispose();
        return image;
    }
}
